package com.zxxy.gulimall.product.web;

import com.zxxy.gulimall.product.entity.CategoryEntity;
import com.zxxy.gulimall.product.service.CategoryService;
import com.zxxy.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.management.ObjectName;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        // 查询所有的一级分类
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();

        model.addAttribute("categorys",categoryEntities);

        // 视图解析器进行拼串   classpath:/templates/+返回值 +.html
        return "index";
    }

    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catelog2Vo>> getCatalogJson(Model model){
        // 查询所有的一级分类
        Map<String, List<Catelog2Vo>> map = categoryService.getCatalogJson();
        System.out.println("-------------"+map.size());
        System.out.println("-------------"+map);
        // 视图解析器进行拼串   classpath:/templates/+返回值 +.html
        return map;
    }

}
